package experiments

import java.io.{File, FilenameFilter, PrintWriter}

//import mulan.classifier.transformation.{BinaryRelevance, ClassifierChain, MultiLabelStacking}
//import mulan.data.MultiLabelInstances
//import mulan.evaluation.Evaluator
import scala.collection.JavaConversions._

/**
  * Created by Alex on 2016/7/31.
  */
object Exp {
  def main(args:Array[String]): Unit ={
//    val path = "D:\\run"
//    val f = new File(path)
//    val xmlFiles = f.list().filter(x=>x.endsWith(".arff")).map(name=> new File(path,name)).sortBy(f=>f.length()).toStream.map(
//      arffFile =>{
//        val nameNoEx = arffFile.getName.split("\\.")(0)
//        val xmlFile = new File(path,nameNoEx+".xml")
//        val multInstances = new MultiLabelInstances(arffFile.getAbsolutePath,xmlFile.getAbsolutePath)
//        (multInstances,nameNoEx)
//      }
//    ).foreach(insts_name=>{
//      val insts = insts_name._1
//      val fileSave = "D:\\wekadataset\\output\\"+insts_name._2
//      val writer = new PrintWriter(new File(fileSave))
//
//      val learn1 = new MultiLabelStacking()
//      val learn2 = new BinaryRelevance(new J48())
//      val learn3 = new ClassifierChain()
//      Array(learn1,learn2,learn3).toStream.foreach(learner=>{
//        learner.setDebug(true)
//        val eval = new Evaluator();
//        saveFile(String.format("evaluating 10 cv using [%s],with dataset [%s]  \n",learner.getClass.toString,insts.getDataSet.relationName()),writer)
//        val results = eval.crossValidate(learner, insts, 10);
//        for(e<-results.getEvaluations){
//                 saveFile(e.toString,writer)
//        }
//        saveFile("========================================================\n",writer)
//      })
//
//    })
//    xmlFiles.filter(name=>name.endsWith(".xml")).toStream.map(xmlname=>{
//      val name = xmlname.split("\\.")(0)
//      val xmlFile = path + "\\" + xmlname;
//      var arffFile = path+"\\"+name+".arff"
//      val arff = new File(arffFile)
//      if(!arff.exists()){
//
//      }
//      val multInstances = new MultiLabelInstances(arffFile,xmlFile)
//      val fileSave = "D:\\wekadataset\\output\\"+name
//      (multInstances,fileSavarffFile = path+"\\"+name+"-train.arff"e)
//    })
      //par.foreach(t=>{
//      MultiLabelStacking
//      BinaryRelevance
//      ClassifierChain
//        val learn1 = new MultiLabelStacking()
//        val learn2 = new BinaryRelevance(new J48())
//        val learn3 = new ClassifierChain()
//        learn1.setDebug(true)
//        learn2.setDebug(true)
//        learn3.setDebug(true)
//
//        val instances = t._1
//        val saveString = t._2
//        val writer = new PrintWriter(new File(saveString))
//      //MultipleEvaluation
//        val learns = Array(learn1,learn2,learn3)
//      learns.foreach(model=>{
//        val eval = new Evaluator();
//        saveFile(String.format("evaluating 10 cv using [%s],with dataset [%s]  \n",model.getClass.toString,instances.getDataSet.relationName()),writer)
//        val results = eval.crossValidate(model, instances, 10);
//        for(e<-results.getEvaluations){
//          saveFile(e.toString,writer)
//        }
//      })
 //   })
  }

  def saveFile( info:String, writer:PrintWriter){
    writer.write(info)
    writer.flush()
    println(info)
  }
}
